/**
 * 工作流 API 使用示例
 * 展示如何使用各种工作流 API
 */

import { WorkflowManager } from './workflowManager'

// 示例：SPA生图（手写提示词）
export async function exampleSpaTextGeneration() {
  try {
    console.log('开始 SPA 生图...')
    
    const result = await WorkflowManager.spaTextGenerate(
      '一个豪华的SPA中心，现代简约风格，温暖的灯光，大理石装饰',
      {
        negativePrompt: '低质量，模糊，变形',
        width: 1024,
        height: 1024,
        steps: 20,
        cfg: 7.0,
        seed: 12345,
        onProgress: (progress) => {
          console.log(`进度: ${progress.process}% - ${progress.msg}`)
        }
      }
    )
    
    console.log('SPA 生图完成:', result)
    return result
  } catch (error) {
    console.error('SPA 生图失败:', error)
    throw error
  }
}

// 示例：SPA生图（风格参考）
export async function exampleSpaStyleGeneration(styleImage: File) {
  try {
    console.log('开始 SPA 风格生图...')
    
    const result = await WorkflowManager.spaStyleGenerate(
      '一个豪华的SPA中心，现代简约风格',
      styleImage,
      {
        negativePrompt: '低质量，模糊，变形',
        width: 1024,
        height: 1024,
        steps: 20,
        cfg: 7.0,
        onProgress: (progress) => {
          console.log(`进度: ${progress.process}% - ${progress.msg}`)
        }
      }
    )
    
    console.log('SPA 风格生图完成:', result)
    return result
  } catch (error) {
    console.error('SPA 风格生图失败:', error)
    throw error
  }
}

// 示例：光线修改
export async function exampleLightModify(inputImage: File) {
  try {
    console.log('开始光线修改...')
    
    const result = await WorkflowManager.lightModify(inputImage, {
      prompt: '调整光线，增加温暖感',
      intensity: 1.2,
      temperature: 0.3,
      contrast: 1.1,
      onProgress: (progress) => {
        console.log(`进度: ${progress.process}% - ${progress.msg}`)
      }
    })
    
    console.log('光线修改完成:', result)
    return result
  } catch (error) {
    console.error('光线修改失败:', error)
    throw error
  }
}

// 示例：单图指令编辑
export async function exampleSingleEdit(inputImage: File) {
  try {
    console.log('开始单图编辑...')
    
    const result = await WorkflowManager.singleEdit(
      inputImage,
      '将背景改为海滩场景，保持人物不变',
      {
        negativePrompt: '低质量，变形',
        strength: 0.8,
        steps: 20,
        cfg: 7.0,
        onProgress: (progress) => {
          console.log(`进度: ${progress.process}% - ${progress.msg}`)
        }
      }
    )
    
    console.log('单图编辑完成:', result)
    return result
  } catch (error) {
    console.error('单图编辑失败:', error)
    throw error
  }
}

// 示例：双图编辑参考风格
export async function exampleDoubleEdit(inputImage: File, styleImage: File) {
  try {
    console.log('开始双图编辑...')
    
    const result = await WorkflowManager.doubleEdit(
      inputImage,
      styleImage,
      '将目标图片应用参考图片的艺术风格',
      {
        negativePrompt: '低质量，变形',
        styleStrength: 0.8,
        steps: 20,
        cfg: 7.0,
        onProgress: (progress) => {
          console.log(`进度: ${progress.process}% - ${progress.msg}`)
        }
      }
    )
    
    console.log('双图编辑完成:', result)
    return result
  } catch (error) {
    console.error('双图编辑失败:', error)
    throw error
  }
}

// 示例：台球生图（手写提示词）
export async function exampleBilliardsTextGeneration() {
  try {
    console.log('开始台球生图...')
    
    const result = await WorkflowManager.billiardsTextGenerate(
      '一个专业的台球室，绿色台球桌，温暖的灯光，复古风格',
      {
        negativePrompt: '低质量，模糊，变形',
        width: 1024,
        height: 1024,
        steps: 20,
        cfg: 7.0,
        onProgress: (progress) => {
          console.log(`进度: ${progress.process}% - ${progress.msg}`)
        }
      }
    )
    
    console.log('台球生图完成:', result)
    return result
  } catch (error) {
    console.error('台球生图失败:', error)
    throw error
  }
}

// 示例：图生视频
export async function exampleImageToVideo(inputImage: File) {
  try {
    console.log('开始图生视频...')
    
    const result = await WorkflowManager.imageToVideo(inputImage, {
      prompt: '镜头缓慢推进，展现细节',
      videoLength: 3,
      fps: 24,
      motionStrength: 1.0,
      onProgress: (progress) => {
        console.log(`进度: ${progress.process}% - ${progress.msg}`)
      }
    })
    
    console.log('图生视频完成:', result)
    return result
  } catch (error) {
    console.error('图生视频失败:', error)
    throw error
  }
}

// 示例：局部重绘
export async function exampleInpainting(inputImage: File, maskImage: File) {
  try {
    console.log('开始局部重绘...')
    
    const result = await WorkflowManager.inpainting(
      inputImage,
      maskImage,
      '在指定区域添加一朵美丽的花朵',
      {
        negativePrompt: '低质量，变形',
        strength: 0.8,
        steps: 20,
        cfg: 7.0,
        onProgress: (progress) => {
          console.log(`进度: ${progress.process}% - ${progress.msg}`)
        }
      }
    )
    
    console.log('局部重绘完成:', result)
    return result
  } catch (error) {
    console.error('局部重绘失败:', error)
    throw error
  }
}

// 示例：瑜伽生图（手写提示词）
export async function exampleYogaTextGeneration() {
  try {
    console.log('开始瑜伽生图...')
    
    const result = await WorkflowManager.yogaTextGenerate(
      '一个宁静的瑜伽工作室，自然光线，木质地板，瑜伽垫',
      {
        negativePrompt: '低质量，模糊，变形',
        width: 1024,
        height: 1024,
        steps: 20,
        cfg: 7.0,
        onProgress: (progress) => {
          console.log(`进度: ${progress.process}% - ${progress.msg}`)
        }
      }
    )
    
    console.log('瑜伽生图完成:', result)
    return result
  } catch (error) {
    console.error('瑜伽生图失败:', error)
    throw error
  }
}

// 示例：迁移
export async function exampleMigration(inputImage: File, styleImage: File) {
  try {
    console.log('开始风格迁移...')
    
    const result = await WorkflowManager.migration(inputImage, styleImage, {
      prompt: '将目标图片应用参考图片的艺术风格',
      styleStrength: 0.8,
      steps: 20,
      cfg: 7.0,
      onProgress: (progress) => {
        console.log(`进度: ${progress.process}% - ${progress.msg}`)
      }
    })
    
    console.log('风格迁移完成:', result)
    return result
  } catch (error) {
    console.error('风格迁移失败:', error)
    throw error
  }
}

// 示例：高清放大（gemini）
export async function exampleUpscaleGemini(inputImage: File) {
  try {
    console.log('开始高清放大...')
    
    const result = await WorkflowManager.upscaleGemini(inputImage, {
      scaleFactor: 2,
      modelName: '003_realSR_BSRGAN_DFOWMFC_s64w8_SwinIR-L_x4_GAN.pth',
      onProgress: (progress) => {
        console.log(`进度: ${progress.process}% - ${progress.msg}`)
      }
    })
    
    console.log('高清放大完成:', result)
    return result
  } catch (error) {
    console.error('高清放大失败:', error)
    throw error
  }
}

// 示例：批量执行工作流
export async function exampleBatchExecution() {
  try {
    console.log('开始批量执行工作流...')
    
    const workflows = [
      {
        type: 'spa-text' as const,
        params: {
          prompt: '一个豪华的SPA中心',
          width: 1024,
          height: 1024
        }
      },
      {
        type: 'billiards-text' as const,
        params: {
          prompt: '一个专业的台球室',
          width: 1024,
          height: 1024
        }
      }
    ]
    
    const results = await WorkflowManager.batchExecute(workflows)
    
    console.log('批量执行完成:', results)
    return results
  } catch (error) {
    console.error('批量执行失败:', error)
    throw error
  }
}

// 示例：获取工作流信息
export function exampleGetWorkflowInfo() {
  const workflows = WorkflowManager.getAvailableWorkflows()
  console.log('可用工作流:', workflows)
  
  workflows.forEach((type: any) => {
    const info = WorkflowManager.getWorkflowInfo(type)
    console.log(`${type}:`, info)
  })
}

